package com.hbsx.why;

import android.view.View;
import android.widget.TextView;

import com.hbsx.why.ui.ApkDownloadActivity;
import com.hbsx.why.ui.DemoCacheActivity;
import com.hbsx.why.ui.DemoPhotoPickTake;
import com.hbsx.why.ui.DemoPictureCompress;
import com.hbsx.why.ui.DemoPushMessage;
import com.hbsx.why.ui.DemoRecycleViewActivity;
import com.hbsx.why.ui.DemoRefreshListView;
import com.hbsx.why.ui.DemoRefreshScrollView;
import com.hbsx.why.base.BaseActivity;
import com.hbsx.why.ui.DemoZxingActivity;
import com.hbsx.why.ui.WebViewActivity;
import com.hbsx.why.utils.LogUtils;
import com.hbsx.why.utils.changeskin.SkinManager;
import com.hbsx.why.utils.refresh.PullScrollView;
import com.hbsx.why.utils.refresh.PullToRefreshLayout;
import com.hbsx.why.views.BackButton;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by 41440 on 2017/6/28.
 */

public class DemoMain extends BaseActivity {
    @BindView(R.id.btn_back)
    BackButton btnBack;
    @BindView(R.id.tv_topTitle)
    TextView tvTopTitle;
    @BindView(R.id.demo_main_scrollview)
    PullScrollView pullScrollView;
    @BindView(R.id.pullToRefreshLayout)
    PullToRefreshLayout mPullToRefreshLayout;

    @Override
    protected void initView() {
        btnBack.setVisibility(View.GONE);
        tvTopTitle.setText("测试刷新数据与加载更多");
        pullScrollView.setPullDownEnable(true);
        pullScrollView.setPullUpEnable(true);
        pullScrollView.canPullUp();
        pullScrollView.canPullDown();
        mPullToRefreshLayout.setOnRefreshListener(new PullToRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh(PullToRefreshLayout pullToRefreshLayout) {
                pullToRefreshLayout.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        mPullToRefreshLayout.refreshFinish(true);
                        toast_short("onRefresh");
                    }
                }, 1000); // (x/1000)秒后刷新

            }

            @Override
            public void onLoadMore(PullToRefreshLayout pullToRefreshLayout) {
                mPullToRefreshLayout.loadMoreFinish(true);
                toast_short("onLoadMore");
            }
        });
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.demo_activity_main;
    }

    @OnClick({R.id.demo_scrollview_refresh, R.id.demo_listview_refresh, R.id.chang_skig, R.id.TabmainActivity,
            R.id.NormalMainActivity, R.id.webview_text, R.id.demo_yasuo, R.id.demo_perssion_and_update,R.id.demo_push_message,
            R.id.demo_photo_take_pick, R.id.demo_cache,R.id.demo_recycleview_refresh,R.id.demo_zxing})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.demo_scrollview_refresh:
                launch(DemoRefreshScrollView.class);
                break;
            case R.id.demo_listview_refresh:
                launch(DemoRefreshListView.class);
                break;
            case R.id.demo_recycleview_refresh:
                launch(DemoRecycleViewActivity.class);
                break;
            case R.id.TabmainActivity:
                launch(TabMainActivity.class);
                break;
            case R.id.NormalMainActivity:
                launch(NormalMainActivity.class);
                break;
            case R.id.webview_text:
                launch(WebViewActivity.class);
                break;
            case R.id.demo_yasuo:
                launch(DemoPictureCompress.class);
                break;
            case R.id.chang_skig:
                String skin_key = SkinManager.getInstance().getChangeSkin();
                LogUtils.loge("------------->" + skin_key);
                if (skin_key != null && skin_key.length() > 0) {
                    if ("one".equals(skin_key)) {
                        SkinManager.getInstance().changeSkin("two");
                    } else if ("two".equals(skin_key)) {
                        SkinManager.getInstance().changeSkin("one");
                    }
                } else {
                    SkinManager.getInstance().changeSkin("two");
                }
                break;
            case R.id.demo_perssion_and_update:
                launch(ApkDownloadActivity.class);
                break;

            case R.id.demo_photo_take_pick:
                launch(DemoPhotoPickTake.class);
                break;
            case R.id.demo_push_message:
                launch(DemoPushMessage.class);
                break;
            case R.id.demo_cache:
                launch(DemoCacheActivity.class);
                break;
            case R.id.demo_zxing:
                launch(DemoZxingActivity.class);
                break;

        }
    }
}
